package yescorp.com.tuixiangzi;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

public  class GameBitmaps {
    public static  Bitmap mWallBitmap;
    public static  Bitmap mManBitmap;
    public static  Bitmap mBoxBitmap;
    public static  Bitmap mFlagBitmap;
    public static  Bitmap mDoneBitmap;
    public static  Bitmap mSoundOpenBitmap;
    public static  Bitmap mSoundCloseBitmap;

    public static void loadBitmaps(Resources res) {
        if (mBoxBitmap == null)
            mBoxBitmap = BitmapFactory.decodeResource(res, R.drawable.icons8_box_48);
        if (mManBitmap == null)
            mManBitmap = BitmapFactory.decodeResource(res, R.drawable.that_girl_demo);
        if (mFlagBitmap == null)
            mFlagBitmap = BitmapFactory.decodeResource(res, R.drawable.icons8_flag_48);
        if (mWallBitmap == null)
            mWallBitmap = BitmapFactory.decodeResource(res, R.drawable.icons8_wall_48);
        if (mDoneBitmap == null)
            mDoneBitmap = BitmapFactory.decodeResource(res, R.drawable.icons8_checkmark_72);
        if (mSoundOpenBitmap == null)
            mSoundOpenBitmap = BitmapFactory.decodeResource(res, R.drawable.icons8_audio_48);
        if (mSoundCloseBitmap == null)
            mSoundCloseBitmap = BitmapFactory.decodeResource(res, R.drawable.icons8_no_audio_48);
    }

    public static void releaseBitmaps(){
        //game board
        releaseBmp(mBoxBitmap);
        releaseBmp(mManBitmap);
        releaseBmp(mWallBitmap);
        releaseBmp(mFlagBitmap);
        releaseBmp(mDoneBitmap);
        releaseBmp(mSoundOpenBitmap);
        releaseBmp(mSoundCloseBitmap);
    }

    private static void releaseBmp(Bitmap bitmap) {
        if (bitmap != null){
            bitmap.recycle();
            bitmap = null;
        }
    }
}
